﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<%@ page contentType="text/html; charset=utf-8"  language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8" isELIgnored="false"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>后台管理</title>
<script language="javascript" type="text/javascript" src="<%=request.getContextPath()%>/admin/DatePicker/WdatePicker.js"></script>
<link href="<%=request.getContextPath()%>/js/css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" />	
<script src="<%=request.getContextPath()%>/js/jquery.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>
<style>
#OrderDetail
{
 font-size:14px;
}
#OrderDetail .title
{
width:450px;
height:25px;
text-align:center;
border-bottom: #cccccc 1px solid;
clear:both;
padding:10 0 10 0;
}

#OrderDetail .cartinfo
{
width:450px;
height:20px;
text-align:center;
border-bottom: #cccccc 1px dashed;
color:#000000;
clear:both;
margin:10px 0px 10px 0px;
}

#OrderDetail  span
{
dispaly:block;
float:left;
width:80px;
text-align:left;
}

#OrderDetail .name
{
dispaly:block;
float:left;
width:160px;
text-align:left;
margin:2px 0px 0px 40px;
}

#OrderDetail .all_info 
{
	float:right;
   	color: #000000;
	margin-left: 3px;
	margin-top:3px;
	width:70px;
}
#OrderDetail .all_price
{
	float:right;
	color:#FF0000;
	font-size:16px;
	font-weight: bold;
	width:50px;
}

</style>
</head>
<body>
<%SimpleDateFormat formatDate=new SimpleDateFormat("yyyy-MM-dd");
  String today=formatDate.format(new Date());
%>
<form name="order" action="<%=request.getContextPath()%>/admin/queryorder.do" method="post">
<table>
 <tr>
 <td>订单编号:</td><td><input type="text" name=orderno value="${param.orderno}"/></td>
 <td>开始时间:</td><td><input class="Wdate" name="beginDate" type="text" onclick="WdatePicker()"
 <c:if test="${empty param.beginDate}">
   value="<%=today%>"
 </c:if>
 <c:if test="${not empty param.beginDate}">
   value="${param.beginDate}"
 </c:if>
  readonly/></td>
 <td>结束时间:</td><td><input class="Wdate" name="endDate" type="text" onclick="WdatePicker()"  
  <c:if test="${empty param.endDate}">
   value="<%=today%>"
 </c:if>
 <c:if test="${not empty param.endDate}">
   value="${param.endDate}"
 </c:if>
  readonly/></td>
 <td>状态:</td>
 <td><select name="status">
 <option value="5,10,15" <c:if test="${param.status=='5,10,15'}" >selected</c:if> >未完成</option>
 <option value="20"  <c:if test="${param.status=='20'}" >selected</c:if> >已完成</option>
 <option value="0" <c:if test="${param.status=='0'}" >selected</c:if> >已取消</option>
 </select>
 </td>
 <td><input type="submit" value="查询" /></td>
 </tr>
</table>
<table width="%100">
<tr>
<td width="150px">订单编号</td>
<td width="100px">订单金额</td>
<td width="100px">成本</td>
<td width="150px">订单状态</td>
<td width="150px">创建时间</td>
<td width="250px">操作</td>
</tr>
<c:set var="totalprice" value="0" />
<c:set var="totalcost" value="0" />
<c:set var="totalnew" value="0" />
 <c:forEach items="${orders}" var="order">
   <c:set var="totalprice" value="${totalprice+order.totalPrice+order.yfPrice}" />
   <c:set var="totalcost" value="${totalcost+order.costTotalPrice}" />
   <c:if test="${order.status==0}"> 
     <tr id="tr_${order.id}">
      <td><a href="javascript:showOrderDetail('${order.id}');" >${order.orderNo}</a></td>
      <td><fmt:formatNumber value="${order.totalPrice+order.yfPrice}" pattern="0.0" type="number"/></td>
      <td><fmt:formatNumber value="${order.costTotalPrice}" pattern="0.00" type="number"/></td>
      <td>已取消</td>
      <td>${order.createDate}</td>
      <td>
      <input type="button" value="拣货" disabled="true"/>
      <input type="button" value="送货" disabled="true"/>
      <input type="button" value="完成" disabled="true"/>
      </td>
      </tr>
   </c:if>
   <c:if test="${order.status==5}">
     <c:set var="totalnew" value="${totalnew*1+1}" />
     <tr id="tr_${order.id}">
      <td><a href="javascript:showOrderDetail('${order.id}');" >${order.orderNo}</a></td>
       <td><fmt:formatNumber value="${order.totalPrice+order.yfPrice}" pattern="0.0" type="number"/></td>
      <td><fmt:formatNumber value="${order.costTotalPrice}" pattern="0.00" type="number"/></td>
      <td>已下达</td>
      <td>${order.createDate}</td>
      <td>
      <input type="button" value="拣货" onclick="showOrderDetail('${order.id}');"/>
      <input type="button" value="送货" disabled="true"/>
      <input type="button" value="完成" disabled="true"/>
      </td>
      </tr>
   </c:if>
   <c:if test="${order.status==10}">
     <tr id="tr_${order.id}">
      <td><a href="javascript:showOrderDetail('${order.id}');" >${order.orderNo}</a></td>
      <td><fmt:formatNumber value="${order.totalPrice+order.yfPrice}" pattern="0.0" type="number"/></td>
      <td><fmt:formatNumber value="${order.costTotalPrice}" pattern="0.00" type="number"/></td>
      <td>拣货中</td>
      <td>${order.createDate}</td>
      <td>
      <input type="button" value="拣货" disabled="true"/>
      <input type="button" value="送货" onclick="saveOrder('${order.id}',15);"/>
      <input type="button" value="完成" disabled="true"/>
      </td>
      </tr>
   </c:if>
 
  <c:if test="${order.status==15}">
     <tr id="tr_${order.id}">
      <td><a href="javascript:showOrderDetail('${order.id}');" >${order.orderNo}</a></td>
      <td><fmt:formatNumber value="${order.totalPrice+order.yfPrice}" pattern="0.0" type="number"/></td>
      <td><fmt:formatNumber value="${order.costTotalPrice}" pattern="0.00" type="number"/></td>
      <td>送货中</td>
      <td>${order.createDate}</td>
      <td>
      <input type="button" value="拣货" disabled="true"/>
      <input type="button" value="送货" disabled="true"/>
      <input type="button" value="完成"  onclick="saveOrder('${order.id}',20);"/>
      </td>
      </tr>
   </c:if>
  <c:if test="${order.status==20}">
     <tr id="tr_${order.id}">
      <td><a href="javascript:showOrderDetail('${order.id}');" >${order.orderNo}</a></td>
      <td><fmt:formatNumber value="${order.totalPrice+order.yfPrice}" pattern="0.0" type="number"/></td>
      <td><fmt:formatNumber value="${order.costTotalPrice}" pattern="0.00" type="number"/></td>
      <td>已完成</td>
      <td>${order.createDate}</td>
      <td>
      <input type="button" value="拣货" disabled="true"/>
      <input type="button" value="送货" disabled="true"/>
      <input type="button" value="完成" disabled="true"/>
      </td>
      </tr>
   </c:if>

 </c:forEach>
</table>
<table width="%100">
<tr><td>合计收款:<fmt:formatNumber value="${totalprice}" pattern="0.0" type="number"/>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp合计成本:<fmt:formatNumber value="${totalcost}" pattern="0.0" type="number"/>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp利润:<fmt:formatNumber value="${totalprice-totalcost}" pattern="0.0" type="number"/></td></tr>
</table>
</form>
 <div  id="OrderDetail" title="拣货"></div>
</body>
</html>
<script>

var printorder;
var refresh=true;
//显示订单详情
function showOrderDetail(orderId)
{
  refresh=false;
  var url='<%=request.getContextPath()%>/order/querydetail.do?method=queryOrderDetail&orderId='+orderId;
	 $.get(url, function(result){	
	    var order=eval('('+result+')');	 
	    printorder=order;   
	    var order_html='<div class="title">'
	    +'<span class="name" >商品名称 </span>'
	    +'<span class="price" >单价</span>'
	    +'<span class="no">数量</span>'
	    +'<span class="total">小计</span>'	      
	    +'</div>';
       for(i=0;i<order.orderDetail.length;i++)
        {
         var detail=order.orderDetail[i];
         var div_html='';
         if(detail.kind=='0')
         {
         div_html='<div class="cartinfo" id='+detail.goodsno+' num=0>'
         +'<span class="name">'+detail.name+'</span>'
         +'<span class="price">￥'+detail.price+'</span>'
         +'<span class="no">'+detail.num+'</span>'
         +'<span class="total">￥'+(detail.totalprice*1).toFixed(1)+'</span>'
         +'</div>';     
         }
         else if(detail.kind=='1')
         {
          div_html='<div class="cartinfo">'
         +'<span class="name">'+detail.name+'</span>'
         +'<span class="price">'+detail.score+'积分</span>'
         +'<span class="no">'+detail.num+'</span>'
         +'<span class="total">'+detail.totalscore+'积分</span>'
         +'</div>';         
         }
         order_html=order_html+div_html;
       }
            
      order_html=order_html+'<div style="width:450px;height:30px">';
      var totalprice=order.order.price;
     if(order.order.yf>0)
      {
       order_html=order_html+'<span class="all_info">+ 运费'+order.order.yf+'元</span>';
      }
     order_html=order_html+'<span class="all_price">￥'+(totalprice*1).toFixed(1)+'</span><span class="all_info">金额总计:</span>';
     if(order.order.score>0)
      {
       order_html=order_html+'<span class="all_info">积分:'+order.order.score+'</span>';
      }
    order_html=order_html+'</div>';
    order_html=order_html+'<div style="width:450px;height:15px" class="error" id="order_error_info"></div>'
    order_html=order_html+'<div style="width:450px;height:60px">'; 
    order_html=order_html+'<div style="float:left;width:300px;margin-left:10px">';
    order_html=order_html+'<div style="height:30px;text-align:left">收货人:'+order.order.relname+'    联系电话：'+order.order.tel+'</div>';
    order_html=order_html+'<div style="height:30px;text-align:left">收货地址：'+order.order.address+'</div>';
    order_html=order_html+'</div>';
    order_html=order_html+'<div style="float:left;width:140px;margin-left:0px">';
    order_html=order_html+'<input type="button" value="打 印" onclick="toprint('+orderId+');" style="width:60px;height:30px"/>';
    if(order.order.status==5)
    {  
    order_html=order_html+'<input id="yes"  type="button" value="确 认" onclick="saveOrder('+orderId+',10);" style="width:60px;height:30px;display:none"/>';
    }
    order_html=order_html+'<input type="text" id="goodscode" name="goodscode" onkeydown="keyfilter();"  style="width:140px;"/>';
    order_html=order_html+'</div>';
    order_html=order_html+'</div>';
    if(order.order.memo!='null' && order.order.memo!='')
    order_html=order_html+'<div style="width:450px;float:left;margin-left:10px;text-align:left;color:red">留言:'+order.order.memo+'</div>';
    order_html=order_html+'</div>';
    $("#OrderDetail").html(order_html);
    $("#OrderDetail").dialog({ height:220+order.orderDetail.length*30});
    $("#OrderDetail").dialog('open');
    $("#goodscode").focus();
 });
}

 function saveOrder(orderId,status)
 {
   var url='<%=request.getContextPath()%>/admin/saveorder.do?tostatus='+status+'&orderId='+orderId;
	 $.get(url, function(result){	
	   $("#OrderDetail").dialog('close');
	  window.location.reload();
	  }); 
 }
 
 function toprint()
 {
   window.open('print.jsp', 'newwindow', 'height=450,width=200,top=100, left=350,toolbar=no,menubar=no, scrollbars=yes, resizable=no,location=no, status=no');
 }

 function keyfilter()
{
  var keycode = event.keyCode;
  if(keycode == 13)
  {
    checkcode($("#goodscode").val());
    if(checkAll())
    {
      $("#yes").show();
    }
    $("#goodscode").val('');
    $("#goodscode").focus();
  }

}

function checkcode(code)
{
  var flag=false;
  $(".cartinfo").each(function(index)
  {   
      if($(this).attr("id")==code)
      {       
        var scannum=$(this).attr("num");
        var bynum=$(this).find(".no").html();
        if($(this).attr("num")==bynum)
        {
          //alert('商品  '+$(this).find(".name").html()+'  的数量已经够了!');
          return true;
        }  
        else if($(this).attr("num")<bynum)
        {
          $(this).attr("num",(scannum*1+1));   
          if($(this).attr("num")==bynum)
          {
           $(this).css("background","green");
          }
          else if($(this).attr("num")<bynum)
          {
            $(this).css("background","red");
          }     
        }       
        flag=true;
        return false;
      }
  });
  
  if(!flag)
  {
   alert("该商品不存在!");  
  }
}

function checkAll()
{
   var flag=true;
   $(".cartinfo").each(function(index)
   {
     var bynum=$(this).find(".no").html();
     if($(this).attr("num")<bynum)
     {
       flag=false;
       return false;
     }  
   });
  return flag;  
}


function myrefresh()
{
if(refresh)
{
  //window.location.reload();
  //document.order.submit();
}
}
//setTimeout('myrefresh()',60000); //指定60秒刷新一次


 //初始化数据
 $(function(){
   $("#OrderDetail").dialog({autoOpen:false,width: 520,height:350,modal:false});

}) ;

</script>
